package com.notary.cms.web.control;

import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.apache.shiro.session.Session;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONArray;
import com.notary.cms.common.annotation.SysLog;
import com.notary.cms.common.controller.AbstractController;
import com.notary.cms.common.entity.Page;
import com.notary.cms.common.entity.R;
import com.notary.cms.common.entity.SysUserEntity;
import com.notary.cms.common.utils.ShiroUtils;
import com.notary.cms.shiro.manager.SysRoleManager;
import com.notary.cms.web.entity.GoodsOrderContact;
import com.notary.cms.web.service.GoodsOrderContactService;

@RestController
@RequestMapping("/goods/giftlist")
public class GoodsOrderContactControl extends AbstractController{

    @Autowired
	private GoodsOrderContactService goodsOrderContactService;
    
    @Autowired
    private SysRoleManager sysRoleManager;
    

    @SysLog("查询列表信息")
    @RequestMapping("/list")
	public Page<GoodsOrderContact> listExhibitionhallForPage(@RequestBody Map<String, Object> params) {
    	
    	SysUserEntity userbean = getUser();
    	List<String> listUserRoles = sysRoleManager.listUserRoles(userbean.getUserId());
		
    	String userRole = JSONArray.toJSONString(listUserRoles);
    	if (userRole.contains("T")) {
    		 userRole = userRole.replace("\"", "").replace("T", "").replace("[", "").replace("]", "");
    			
    			if (StringUtils.isNotEmpty(userRole)) {
    				params.put("channel", userRole);
    				
    			}
		}
		System.out.println(JSONArray.toJSONString(params));
    	
		// TODO Auto-generated method stub
    	Page<GoodsOrderContact>  page=goodsOrderContactService.listGoodsOrderContactForPage(params);
    	
		return page;
	}
    @SysLog("查询单条数据")
    @RequestMapping("/select")
	public R selectByPrimaryKey(@RequestBody Long id) {
		// TODO Auto-generated method stub
		return  goodsOrderContactService.selectByPrimaryKey(id);
	}
    
    @SysLog("更新单条数据")
    @RequestMapping("/edit")
	public R updateGoodsOrderContact(@RequestBody  GoodsOrderContact goodsOrderContact) {
		// TODO Auto-generated method stub
    	System.out.println(JSONArray.toJSONString(goodsOrderContact));
		return goodsOrderContactService.updateByPrimaryKeySelective(goodsOrderContact);
	}

}
